<template>
    <div class="mainDiv">
        <div class="rowHead flex_center">
            <el-button type="success" icon="plus" @click="add" v-qx="permission.add" style="margin-right: 5px;">新增项目</el-button>
            <el-select v-model="page.zt" class="ml" @change="selstatus" v-qx="permission.status" style="margin-right: 5px;">
                <el-option v-for="(s,index) in status" :label="s.txt" :value="s.val" :key="index">
                </el-option>
            </el-select>
            <el-input style="width: 200px" placeholder="搜索项目名称、描述、品牌、分类" @keyup.enter.native="searchList" v-model="page.search">
                <i slot="suffix" class="el-icon-search" style="line-height: 40px;width: 25px;cursor: pointer;" @click="searchList"></i>
            </el-input>
        </div>
        <el-table :data="list" :stripe="true" height="100%">
            <el-table-column prop="id" label="ID" width="100"></el-table-column>
            <el-table-column prop="name" label="项目名称"></el-table-column>
            <el-table-column prop="number" label="项目编号"></el-table-column>
            <el-table-column prop="price" label="标准价格">
                <template slot-scope="scope">{{scope.row.price+'元'}}</template>
            </el-table-column>
            <el-table-column prop="usetime" label="标准用时">
                <template slot-scope="scope">{{scope.row.usetime+'分钟'}}</template>
            </el-table-column>
            <!-- <el-table-column prop="xstdtype" label="销售提成">
                <template slot-scope="scope">
                    <el-tag color="#edaff1" v-if="scope.row.xstdtype==1">{{Number(scope.row.xspercent*100).toFixed(0)+'%'}}</el-tag>
                    <el-tag color="#f3a6bb" v-else>{{scope.row.xsfixed+'元'}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="sgtdtype" label="手工提成">
                <template slot-scope="scope">
                    <el-tag color="#edaff1" v-if="scope.row.sgtdtype==1">{{Number(scope.row.sgpercent*100).toFixed(0)+'%'}}</el-tag>
                    <el-tag color="#f3a6bb" v-else>{{scope.row.sgfixed+'元'}}</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="khtdtype" label="卡耗提成">
                <template slot-scope="scope">
                    <el-tag color="#edaff1" v-if="scope.row.khtdtype==1">{{Number(scope.row.khpercent*100).toFixed(0)+'%'}}</el-tag>
                    <el-tag color="#f3a6bb" v-else>{{scope.row.khfixed+'元'}}</el-tag>
                </template>
            </el-table-column> -->
            <el-table-column prop="bname" label="所属品牌"></el-table-column>
            <el-table-column prop="cname" label="所属分类"></el-table-column>
            <el-table-column prop="remarks" label="项目描述" :show-overflow-tooltip="true"></el-table-column>
            <el-table-column prop="isdisabled" label="状态">
                <template slot-scope="scope">
                    <el-tag type="danger" v-if="scope.row.isdisable">弃用</el-tag>
                    <el-tag type="success" v-else>正常</el-tag>
                </template>
            </el-table-column>
            <el-table-column prop="addtime" label="添加日期" :show-overflow-tooltip="true">
                <template slot-scope="scope">
                    {{time(scope.row.addtime)}}
                </template>
            </el-table-column>
            <el-table-column label="项目操作" width="150">
                <template slot-scope="scope">
                    <el-button-group v-if="!scope.row.isdisable">
                        <el-tooltip content="项目编辑" placement="left" :open-delay="800" v-qx="permission.edit">
                            <el-button type="warning" icon="el-icon-edit" size="mini" @click="edit(scope.row)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="编辑图文" placement="left" :open-delay="800" v-qx="permission.editInfo">
                            <el-button type="success" icon="el-icon-h-document" size="mini" @click="editInfo(scope.row)"></el-button>
                        </el-tooltip>
                        <el-tooltip content="关闭当前项目" placement="top" :open-delay="800" v-qx="permission.unstop">
                            <el-button type="danger" icon="el-icon-h-jinyong" size="mini" @click="stop(scope.row.id,1)"></el-button>
                        </el-tooltip>
                    </el-button-group>
                    <el-tooltip content="重新开启当前项目" placement="left" :open-delay="800" v-else v-qx="permission.unstop">
                        <el-button type="success" icon="el-icon-h-qiyong2" size="mini" @click="stop(scope.row.id,0)"></el-button>
                    </el-tooltip>
                </template>
            </el-table-column>
        </el-table>
        <div>
            <el-pagination @size-change="sizeChange" @current-change="currentChange" :current-page="page.pages" :page-sizes="[15, 30, 50, 100]" :page-size="page.limits" layout="total, sizes, prev, pager, next, jumper" :total="total">
            </el-pagination>
        </div>
    </div>
</template>
<script>
import C from '@/common/common.js'
export default {
  name: 'subject',
  data () {
    return {
      list: [],
      total: 0,
      page: {
        pages: 1,
        limits: 15,
        search: '',
        zt: 0
      },
      status: [{
        txt: '正常',
        val: 0
      }, {
        txt: '停用',
        val: 1
      }],
      permission: {
        add: 'projectcategory_add',
        status: 'projectcategory_status',
        edit: 'projectcategory_edit',
        unstop: 'projectcategory_unstop',
        editInfo: 'projectcategory_editInfo'
      }
    }
  },
  mounted () {
    this.getList()
  },
  methods: {
    async add () {
      let res = await C.openBrowserWindow('/editSubject2', {}, {
        transparent: true,
        frame: false,
        width: 1200,
        height: 900,
        useSpa: false,
        spaModel: 'organization'
      })
      if (res) {
        C.success(res.data)
        this.getList()
      }
    },
    async edit (row) {
      let res = await C.openBrowserWindow('/editSubject2', { row: row }, {
        transparent: true,
        frame: false,
        width: 1200,
        height: 900,
        useSpa: false,
        spaModel: 'organization'
      })
      if (res) {
        C.success(res.data)
        this.getList()
      }
    },
    async editInfo (row) {
      // 编辑项目图文
      C.openBrowserWindow('/editSubjectInfo', { id: row.id }, { width: 835, height: 770 })
    },
    stop: async function (id, st) {
      let that = this
      if (st) {
        C.confirm('停用机构项目, 是否继续?', async () => {
          let res = await C.ajax('/organization/subject/subjectstatus', { id: id, st: st }, 'post')
          if (res) {
            C.success(res.data)
            that.getList()
          }
        })
      } else {
        let res = await C.ajax('/organization/subject/subjectstatus', { id: id, st: st }, 'post')
        if (res) {
          C.success(res.data)
          that.getList()
        }
      }
    },
    refresh: function () {
      window.location.reload()
    },
    selstatus: function () {
      this.getList()
    },
    sizeChange: function (val) {
      this.page.limits = val
      this.getList()
    },
    currentChange: function (val) {
      this.page.pages = val
      this.getList()
    },
    searchList: function () {
      this.getList()
    },
    getList: async function () {
      let that = this
      let data = await C.ajax('/organization/subject/subjectlist', this.page, 'post')
      if (data) {
        that.list = data.data
        that.total = data.count
      }
    },
    time: function (unix) {
      return C.times(unix)
    }
  }
}
</script>